import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { EToplistType } from "../../../../Message/Public/EToplistType";
import { WuXingRankItem } from "./WuXingRankItem";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class WuXingRankSprite
    
    export  class WuXingRankSprite /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._itemArr = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._headTf = new GTextFormat("", 12, 16777113);
            this._rankTxt = ObjCreate.createTextField(Language.getString(32063), 0, 0, 30, 30, this, this._headTf);
            this._nameTxt = ObjCreate.createTextField(Language.getString(32064), 85, 0, 30, 30, this, this._headTf);
            this._careerTxt = ObjCreate.createTextField(Language.getString(32066), 195, 0, 30, 30, this, this._headTf);
            this._attributeTxt = ObjCreate.createTextField(Language.getString(32043), 285, 0, 80, 30, this, this._headTf);
            this._rangeTxt = ObjCreate.createTextField(Language.getString(32070), 405, 0, 60, 30, this, this._headTf);
            var loc1=ObjCreate.createBg(0, 23, 460, 2, this, ImagesConst.SplitLine);
            this.createItem();
            return;
        }

        public resetTextPos(arg1: int): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EToplistType._EToplistTypeWuXingFight:
                {
                    this._attributeTxt.text = Language.getString(32043);
                    break;
                }
                case EToplistType._EToplistTypeWuXingAttributeMax:
                {
                    this._attributeTxt.text = Language.getString(32111);
                    break;
                }
                case EToplistType._EToplistTypeWuXingEnergy:
                {
                    this._attributeTxt.text = Language.getString(32045);
                    break;
                }
                case EToplistType._EToplistTypeMountEquip:
                {
                    this._attributeTxt.text = Language.getString(32047);
                    break;
                }
            }
            return;
        }

        /* internal  */createItem(): void
        {
            var loc2=0;
            var loc3=null;
            var loc1=0;
            loc2 = 30;
            var loc4=0;
            while (loc4 < 10) 
            {
                loc3 = new WuXingRankItem();
                loc3.x = loc1;
                loc3.y = loc2;
                loc2 = loc2 + loc3.height;
                loc3.doubleClickEnabled = true;
                this._itemArr.push(loc3);
                loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
                loc3.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClickItemHandler);
                addChild(loc3);
                ++loc4;
            }
            return;
        }

        public get curTopList(): TToplist
        {
            return this._curTopList;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as WuXingRankItem;
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                ++loc2;
            }
            loc1 = arg1.target as WuXingRankItem;
            if (this._curTopList && !(loc1.playerId == this._curTopList.entityId)) 
            {
                loc1.onItemLookupPlayerClick(arg1);
            }
            else if (this._curTopList) 
            {
                loc1.drawGrayColor();
            }
            this._curTopList = loc1.data;
            return;
        }

        /* internal  */onDoubleClickItemHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as WuXingRankItem;
            loc1.onItemDoubleClickShowPlayerMenu();
            return;
        }

        public setData(arg1: Array<any>, arg2: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as WuXingRankItem;
                loc1.updateItem(arg1[loc2], arg2);
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                ++loc2;
            }
            if (this._itemArr && this._itemArr.length > 0) 
            {
                this._curTopList = null;
                loc1 = this._itemArr[0] as WuXingRankItem;
                if (loc1.data != null) 
                {
                    loc1.drawGrayColor();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LookUpTargetEquip, loc1.sEntityId));
                    this._curTopList = loc1.data;
                }
            }
            return;
        }

        public showTargetPlayer(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as WuXingRankItem;
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                if (loc1.rank == arg1) 
                {
                    loc1.drawGrayColor();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.LookUpTargetEquip, loc1.sEntityId));
                }
                ++loc2;
            }
            return;
        }

        public setItemOnlineState(arg1: int, arg2: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as WuXingRankItem;
                if (loc1.data == null) 
                {
                    return;
                }
                if (loc1.playerId == arg1) 
                {
                    loc1.registerPlayerMenu(arg2);
                    return;
                }
                ++loc2;
            }
            return;
        }

        /* internal */ /* var */_headTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_careerTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_attributeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rangeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_curTopList: TToplist;
    }
